<%@page import="com.nebula.common.Const"%>
<%@page import="com.nebula.pojo.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
	User user = (User) session.getAttribute(Const.USERINFO);
 %>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="static/html5shiv.js"></script>
<script type="text/javascript" src="static/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/style.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/layer/2.4/skin/layer.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/magic-input.min.css" />
<!--[if IE 6]>
<script type="text/javascript" src="static/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>修改密码</title>
</head>
  
<body>
<article class="page-container">
	<form class="form form-horizontal" id="change" action="" name="frm" onsubmit="return false;">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>用户名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" name="username" id="username" disabled="disabled"
					value="<%=user.getUsername()%>" style="width: 800">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>旧密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" autocomplete="off" id="old_pass" maxlength="16"
					name="old_pass" value="" style="width: 800" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>新密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" autocomplete="off" id="new_pass" maxlength="16"
					name="new_pass" value="" style="width: 800" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span
				class="c-red"></span>确认新密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" autocomplete="off" id="renew_pass" maxlength="16"
					name="renew_pass" value="" style="width: 800" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;修改&nbsp;&nbsp;"> &nbsp;
				<input class="btn btn-primary radius" type="reset"  value="&nbsp;&nbsp;重置&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$.validator.addMethod("checkPassword",function(value,element){
		return $("#old_pass").val()!=$("#new_pass").val();
	},"新密码和旧密码不能一致");
	
	$("#change").validate({
		onfocusout:function(element){
			$(element).valid();
		},
		rules:{
			old_pass:{
				required: true,
				maxlength: "16",
				minlength: "6",
				remote : {
					url : "${pageContext.request.contextPath}/user/check-password.action",
					type : "post",
					data : {
						password : function(){
							return $('#old_pass').val();
						},
					},
					dataFilter:function(data,type){
						var d = $.parseJSON(data);
						if(d.status == 0){
							return true;
						}else{
							return false;
						}
					}
				}
			},
			new_pass:{
				required: true,
				maxlength: "16",
				minlength: "6",
				checkPassword : true
			},
			renew_pass:{
				required:true,
				equalTo: "#new_pass",
				maxlength: "16",
				minlength: "6"
			}
		},
		messages:{
			old_pass:{
				remote : "旧密码不正确！"
			},
			new_pass:{
				equalTo :"新密码和原密码一致",
			},
			renew_pass:{
				equalTo :"两次密码输入不一致",
			}
		},
		onkeyup:false,
		focusCleanup:false,
		success:"valid",
		submitHandler:function(){
			$.ajax({
				type: "post",
				url: "${pageContext.request.contextPath}/user/change-password.action",
				data: {
					password : $("#renew_pass").val()
				},
				dataType: "json",
				success: function(_data){
					if(_data.status == 0){
						layer.msg(_data.msg+",正在为您重新登录,请稍后...",{icon: 6,time:2000,offset: "0"},function(){
							$.ajax({
								type: "post",
								url: "${pageContext.request.contextPath}/user/login.action",
								data: {
									username : '<%=user.getUsername()%>',
									password : $("#new_pass").val(),
								},
								dataType: "json",
								success: function(_data){
									if(_data.status == 0){
										window.parent.location.reload(); 
									}else{
										layer.msg("重新登录失败，请手动登录",{icon:2,time: 2000,offset: "0"},function(){
											window.location.href="${pageContext.request.contextPath}/login.jsp";
										})
									}
								}
							});
						});
					}
				}
			});
		}
	});
});
</script>
</body>
</html>
